"""
演示变量的类型注解
"""

# 基础数据类型注解
import json
import random

var_1: int = 10
var_2: str = "itheima"
var_3: bool = True


# 类对象注解
class Student:
    pass


stu: Student = Student()

# 基础容器类型注解
my_list: list = [1, 2, 3]
my_tuple: tuple = (1, 2, 3)
my_dict: dict = {"itheima": 666}
print(my_list)
print(my_tuple)
print(my_dict)
# 容器类型详细注解
my_list: list[int] = [1, 2, 3]
my_tuple: tuple[int] = (1, 2, 3)
my_dict: dict[str, int] = {"itheima": 666}
my_tuple = (1, "张三", True)
my_dict = {1: "abd"}
print(my_list)
print(my_tuple)
print(my_dict)
# 在注释中进行类型注解
var_4 = random.randint(1, 10)  # type: int
var_5 = json.loads('{"name":"张三"}')  # type: dict[str, str]


def func(a: int, b: int):
    return a * b


var_6 = func(1, 2)  # type:int


def func2(data: list) -> int:
    return max(data)


var_9 = func2([1, 2, 3, 4, 5, 9])
print(var_9)

# 类型注解的限制，类型注解只是备注，并不具有强制性，所以注解与实际值类型不符时，并不会报错，也不影响程序运行
var_7: int = "itheima"
var_8: str = 123
